<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>react</title>
    <style>
      .name {
        font-size: 25px;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>

    <script src="../day01/lib/react.development.js"></script>
    <script src="../day01/lib/react-dom.development.js"></script>
    <script src="../day01/lib/babel.js"></script>

    <script type="text/babel">
      const commentList = [
        {
          id: 1,
          name: "jack",
          content: "rose, you jump i jump",
          time: "03:21",
        },
        {
          id: 2,
          name: "rose",
          content: "jack, you see you, one day day",
          time: "03:22",
        },
        { id: 3, name: "tom", content: "jack,。。。。。", time: "03:23" },
      ];

      // 高阶函数：执行函数返回值是一个新函数
      // 利用高阶函数可以给内部函数传参
      const handleClick = (comment) => {
        return () => {
          alert(comment.time);
        };
      };

      let element;
      if (commentList.length) {
        element = (
          <ul>
            {commentList.map((comment) => {
              return (
                <li key={comment.id}>
                  <h3 className="name">{comment.name}</h3>
                  <p style={{ fontSize: 20 }} onClick={handleClick(comment)}>
                    {comment.content}
                  </p>

                  {/* <p style={{ fontSize: 20 }} onClick={() => alert(comment.time);}> */}
                </li>
              );
            })}
          </ul>
        );
      } else {
        element = <h1>暂无评论</h1>;
      }

      ReactDOM.createRoot(document.getElementById("root")).render(element);
    </script>
  </body>
</html>
